package com.un.ebs.sys.excel;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.un.ebs.inventory.enums.BusinessRelationTypeEnum;
import com.un.ebs.inventory.service.BusinessRelationService;
import com.un.ebs.sys.dto.EntInfoExcelInputDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author liubo
 * @email liubocs@163.com
 * @date 2020/6/7 10:38
 */
public class EntInfoImportListener extends AnalysisEventListener<EntInfoExcelInputDto> {

    private static final Logger LOGGER = LoggerFactory.getLogger(EntInfoImportListener.class);

    private final BusinessRelationService service;

    private final BusinessRelationTypeEnum entType;

    public EntInfoImportListener(BusinessRelationService businessRelationService, BusinessRelationTypeEnum type) {
        this.service = businessRelationService;
        this.entType = type;
    }

    @Override
    public void invoke(EntInfoExcelInputDto data, AnalysisContext analysisContext) {
        //System.out.println(data.getName());
        service.add(data.getName(), entType);
        LOGGER.warn(data.getName());
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        LOGGER.warn("所有数据解析完成！");
    }
}
